#![macro_use]

use magic_query::{parse, Error, Map, ParseResult, QueryAble};

macro_rules! hashmap {
    (@single $($x:tt)*) => (());
    (@count $($rest:expr),*) => (<[()]>::len(&[$(hashmap!(@single $rest)),*]));

    ($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) };
    ($($key:expr => $value:expr),*) => {
        {
            let _cap = hashmap!(@count $($key),*);
            let mut _map = ::std::collections::HashMap::with_capacity(_cap);
            $(
                let _ = _map.insert($key.to_string(),  magic_query::Value::from($value));
            )*
            _map
        }
    };
}

fn main() -> Result<(), Error> {
    let list = vec![
        hashmap!(
            "name" => "Amy22",
            "age" => 12,
            "height" => 166,
            "id" => 2018060502032i64,
        ),
        hashmap!(
            "name" => "沈大智",
            "age" => 25,
            "height" => 175.5,
            "id" => 2018060502038i64,

        ),
        hashmap!(
            "name" => "Cindy33",
            "age" => 20,
            "height" => 170,
            "id" => 2018060502028i64,
        ),
    ];

    let map = Map::from(list);
    let parser: ParseResult = parse!([1=1]-[name=.大智]);
    println!("{:#?}", parser);
    let result = map.query(&parser?)?;

    println!("{:#?}", result);

    Ok(())
}
